package com.ailanyin.common.exception;


import com.ailanyin.common.constant.IErrorCode;

/**
 * 自定义 API异常
 *
 * @author ailanyin
 * @version 1.0
 * @since 2021-08-31
 */
public class ApiException extends RuntimeException {
    private IErrorCode errorCode;

    public ApiException(IErrorCode errorCode) {
        super(errorCode.getMessage());
        this.errorCode = errorCode;
    }

    public ApiException(String message) {
        super(message);
    }

    public ApiException(Throwable cause) {
        super(cause);
    }

    public ApiException(String message, Throwable cause) {
        super(message, cause);
    }

    public IErrorCode getErrorCode() {
        return errorCode;
    }


    /**
     * 不打印堆栈信息, 提高性能
     *
     * @return this
     */
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }
}
